package com.evildog.workspace.life.application.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.evildog.workspace.life.application.bo.DiaryTagBO;
import com.evildog.workspace.life.application.convert.DiaryTagConvert;
import com.evildog.workspace.life.application.dto.DiaryTagDTO;
import com.evildog.workspace.life.application.entity.DiaryTag;
import com.evildog.workspace.life.application.mapper.DiaryTagMapper;
import com.evildog.workspace.life.application.service.DiaryTagService;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;

@Service
public class DiaryTagServiceImpl extends ServiceImpl<DiaryTagMapper, DiaryTag> implements DiaryTagService {

    @Override
    public DiaryTagBO getDetailById(Long id) {
        DiaryTag diaryTag = this.getById(id);
        Assert.notNull(diaryTag, "diaryTag is null!");
        return DiaryTagConvert.INSTANCE.convert(diaryTag);
    }

    @Override
    public boolean save(DiaryTagDTO dto){
        DiaryTag newDiaryTag = DiaryTagConvert.INSTANCE.convert(dto);
        return save(newDiaryTag);
    }

    @Override
    public boolean updateById(Long id, DiaryTagDTO dto){
        DiaryTag oldDiaryTag = getById(id);
        Assert.notNull(oldDiaryTag, "diaryTag is null!");
        DiaryTag newDiaryTag = DiaryTagConvert.INSTANCE.convert(dto);
        newDiaryTag.setId(id);
        return updateById(newDiaryTag);
    }
}
